package org.ushio.nchu_22201408.mapper;

import org.apache.ibatis.annotations.*;
import org.ushio.common_module.entity.User;

import java.util.List;

@Mapper
public interface UserMapper {
    @Results({
            @Result(property = "phoneNumber", column = "Phone_Number"),
            @Result(property = "gender", column = "Gender"),
            @Result(property = "userName", column = "User_Name"),
            @Result(property = "password", column = "Password"),
            @Result(property = "idCardNumber", column = "ID_Card_Number"),
            @Result(property = "address", column = "Address"),
            @Result(property = "banStatus", column = "Ban_Status")
    })
    @Select("SELECT * FROM users WHERE Phone_Number = #{phone_number}")
    User findUserByPhoneNumber(@Param("phone_number") String phoneNumber);

    @Insert("INSERT INTO users(Phone_Number, Gender, User_Name, Password, ID_Card_Number, Address, Ban_Status) " +
            "VALUES(#{phoneNumber}, #{gender}, #{userName}, #{password}, #{idCardNumber}, #{address}, #{banStatus})")
    void insertUser(User user);

    @Update("UPDATE users SET Gender = #{gender}, User_Name = #{userName}, Password = #{password}, ID_Card_Number = #{idCardNumber}, Address = #{address}, Ban_Status = #{banStatus} WHERE Phone_Number = #{phoneNumber}")
    int updateUser(User user);

    @Results({
            @Result(property = "phoneNumber", column = "Phone_Number"),
            @Result(property = "gender", column = "Gender"),
            @Result(property = "userName", column = "User_Name"),
            @Result(property = "password", column = "Password"),
            @Result(property = "idCardNumber", column = "ID_Card_Number"),
            @Result(property = "address", column = "Address"),
            @Result(property = "banStatus", column = "Ban_Status")
    })
    @Select("SELECT * FROM users")
    List<User> findAllUsers();

    @Update("UPDATE users SET Ban_Status = #{banStatus} WHERE Phone_Number = #{phoneNumber}")
    int updateBanStatus(@Param("phoneNumber") String phoneNumber, @Param("banStatus") Integer banStatus);
}